import request from '@/utils/request'
import ApolloClient from "apollo-boost";
import gql from "graphql-tag";

const client = new ApolloClient({
  uri: "http://127.0.0.1:18080/graphql"
});

//定义查询
const QUERY_LIST = gql`
query HouseResourcesList($pageSize: Int, $page: Int, $resourceType:Int) {
  HouseResourcesList(pageSize: $pageSize, page: $page, resourceType: $resourceType) {
    list {
      id
      pic
      title
      coveredArea
      orientation
      floor
      rent
      resourceType
      houseType
      useArea
    }
    ,
    pagination{
      current
      pageSize
      total
    }
  }
}
`;

const QUERY_HOUSE = gql`
    query HouseResources($id :Long) {
        HouseResources(id: $id) {
           
                id
                pic
                title
                coveredArea
                orientation
                floor
                rent
                resourceType
                contact
                mobile
                estateId
                buildingNum
                buildingUnit
                propertyCost
                buildingFloorNum
                houseType
                useArea
                city
                county
                intentions
                address
                facilities
               
        }
    }
`;
export default {
  getList() {
    return request({
      url: `/${group_name}/${api_name}`,
      method: 'get'
    })
  },
  search(page, size, searchMap) {
    console.log(searchMap.resourceType);

    return  client.query({query: QUERY_LIST, variables: {"pageSize":size,"page":page,"resourceType":3}})
  },
  save(pojo) {
    return request({
      url: `/${group_name}/${api_name}`,
      method: 'post',
      data: pojo
    })
  },
  findById(id) {
    return request({
      url: `/${group_name}/${api_name}/${id}`,
      method: 'get'
    })
  },
  update(id, pojo) {
    if (id === null || id === '') {
      return this.save(pojo)
    }
    return request({
      url: `/${group_name}/${api_name}/${id}`,
      method: 'put',
      data: pojo
    })
  },
  deleteById(id) {
    return request({
      url: `/${group_name}/${api_name}/${id}`,
      method: 'delete'
    })
  }
}
